<?php
/**
 * 拼团订单管理
 *
 * @copyright  Copyright (c) 中国追溯
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');
class order_pintuanModel extends Model {
    /**
	 *GET操作
	 * @author Harris
	 ***/
	public function getList($condition, $page=null, $order='log_id desc', $field='*', $limit=0){
		return $this->table('order_pintuan')->field($field)->where($condition)->limit($limit)->page($page)->order($order)->select();
	}	
	
	/**
     * 添加一条订单记录
     * @author Harris
     * */
    public function add($insert){
    	return $this->table("order_pintuan")->insert($insert);
    }
    
    /**
     * 修改一条订单记录
     * @author Harris
     * */
    public function save($where,$update){
    	return $this->table("order_pintuan")->where($where)->update($update);
    }

    /**获取拼团成功时间*/
    public function pintuan_isSuccess($data=array())
    {
        if($data['buyer_type'] == 0){
            $count = $this->table('order_pintuan')->where('pay_time > 0 and buyer_type = '.$data['log_id'])->count();
            if(intval($count+1) >= $data['min_num']){
                $result = $this->table('order_pintuan')->where('buyer_type = '.$data['log_id'])->order('pay_time desc')->find();
                return date('Y-d-m H:i:s',$result['pay_time']);
            }else{
                return false;
            }
        }else{
            $count = $this->table('order_pintuan')->where('pay_time > 0 and buyer_type = '.$data['buyer_type'])->count();
            if(intval($count+1) >= $data['min_num']){
                $result = $this->table('order_pintuan')->where('buyer_type = '.$data['buyer_type'])->order('pay_time desc')->find();
                return date('Y-d-m H:i:s',$result['pay_time']);
            }else{
                return false;
            }
        }
    }
    /**
     * 查询一条订单记录
     * @author Harris
     * */
    public function one_data($condition, $field='*'){
        return $this->table("order_pintuan")->field($field)->where($condition)->find();
    }
}

	
